import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("StatefullWidget"),
      ),
      body: MyHomePageBody("当前计数"),
    );
  }
}

class MyHomePageBody extends StatefulWidget {
  final title;
  MyHomePageBody(this.title);
  @override
  _MyHomePageBodyState createState() => _MyHomePageBodyState();
}

class _MyHomePageBodyState extends State<MyHomePageBody> {
  int number = 0;
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                setState(() {
                  number++;
                });
              },
              child: Text("+"),
            ),
            ElevatedButton(
              onPressed: () {
                setState(() {
                  number--;
                });
              },
              child: Text("-"),
            )
          ],
        ),
        Text("${widget.title}${number}"),
      ],
    );
  }
}
